package com.wshl.aijiuunion.utils;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.view.View;

import com.wshl.aijiuunion.R;

/**
 * Created buy 风凊扬 on 2019/10/22 0022
 * 图片合成
 */
public class ImageUnionUtil {

    public static Bitmap compoundBitmap(Bitmap BitmapOne, Bitmap BitmapTwo) {
        Bitmap newBitmap = null;
        newBitmap = Bitmap.createBitmap(BitmapOne);
        Canvas canvas = new Canvas(newBitmap);
        Paint paint = new Paint();
        int w = BitmapOne.getWidth();
        int h = BitmapOne.getHeight();
        int w_2 = BitmapTwo.getWidth();
        int h_2 = BitmapTwo.getHeight();
        //BitmapOne.getHeight(), paint);
        paint = new Paint();
        //设置第二张图片的 左、上的位置坐标
        canvas.drawBitmap(BitmapTwo, 16,
                h - 16 - h_2, paint);
        canvas.save();
        // 存储新合成的图片
        canvas.restore();
        return newBitmap;
    }

//    public void compoundImage(View v) {
//        Bitmap bitmap1 = ((BitmapDrawable) getResources().getDrawable(R.drawable.apple)).getBitmap();
//        Bitmap bitmap2 = ((BitmapDrawable) getResources().getDrawable(R.drawable.go)).getBitmap();
//        Drawable[] array = new Drawable[2];
//        array[0] = new BitmapDrawable(bitmap1);
//        array[1] = new BitmapDrawable(bitmap2);
//        LayerDrawable la = new LayerDrawable(array); // 其中第一个参数为层的索引号，后面的四个参数分别为left、top、right和bottom la.setLayerInset(0, 0, 0, 0, 0); la.setLayerInset(1, 20, 20, 20, 20); image.setImageDrawable(la); }作者：青青河边踩
//        // 其中第一个参数为层的索引号，后面的四个参数分别为left、top、right和bottom
//        la.setLayerInset(0, 0, 0, 0, 0);
//        la.setLayerInset(1, 20, 20, 20, 20);
//    }

}
